from db.db_platform import PostgresqlDB, MysqlDB
from db.db_properties import DBProperties
from db.db_export import ExportField


def ignore_table_fun(table_name, table_name_c):
    ignore_prefix = ['d', 'm', 'p', 's', 'ta', 'tb', 'te']
    start_with = False
    for ignore in ignore_prefix:
        if table_name.startswith(ignore):
            start_with = True
            continue
    return start_with and table_name_c is None


if __name__ == '__main__':
    # postgresql 数据库测试导出,指定忽略要导出的表和指定导出public这个schema下的表
    # postgre_prop = DBProperties('testdb', 'testuser', 'testmm', 'localhost', '5432',
    #                             ignore_table_fun=ignore_table_fun, schema="public")
    # db = PostgresqlDB(postgre_prop)
    # db.init_data()
    # db.export_md(r"C:\Users\tanyuanchao\Desktop\export")

    # mysql数据库测试导出
    prostgre_pro = DBProperties('ry-cloud', 'root', '123456', 'localhost', '3306')
    db = MysqlDB(prostgre_pro)
    db.init_data()
    db.export_md(r"C:\Users\tanyuanchao\Desktop\export",
                 export_fields=(
                 ExportField(name='name', c_name='参数类型'), ExportField(name='type'), ExportField(name='length'),
                 ExportField(name='nullable',
                             # 自定义字段格式换函数，每个是否可空后面加一个---test
                             format_fun=lambda field, fields_dict: str(fields_dict['nullable']) + "---test"),
                 ExportField(name='desc')))
